<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>老师管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
		<!--搜索开始-->
        <fieldset class="layui-elem-field layuimini-search">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" id="searchFrm">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">老师名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
					</div>
					<div class="layui-form-item">
                        <div class="layui-block" style="text-align: center;">
                            <a class="layui-btn " lay-submit=""  lay-filter="data-search-btn"><label class="layui-icon layui-icon-search"></label>搜索</a>
							<a class="layui-btn layui-btn-warm" onclick="javascript:$('#searchFrm')[0].reset()" lay-filter="data-search-btn"><label class="layui-icon layui-icon-refresh"></label>重置</a>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
		<!--搜索结束-->
		
		<!--表格开始-->
        <table class="layui-hide" id="noticeTable" lay-filter="noticeTable"></table>
		<script type="text/html" id="noticeTableBar">
			<a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete" lay-event="update">课程教学</a>
		</script>
		<!--表格结束-->
		
		<!--选择菜单和权限的弹出层开始-->
		<div id="selectRoleDiv" style="display: none;padding: 0.3125rem;">
			<table class="layui-hide" id="roleTable" lay-filter="roleTable"></table>
		</div>
    </div>
</div>
<script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="../../../lib/common/jquery.cookie.min.js" charset="utf-8"></script>
<script src="../../../lib/common/common.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'table','laydate','layer','wangEditor'], function () {
        var form = layui.form;
        var table = layui.table;
		var laydate=layui.laydate;
		var layer=layui.layer;
		var  wangEditor = layui.wangEditor;
		
		  var tableIns=table.render({
				elem: '#noticeTable',
				url: api+'personnel/TeacherList',
				toolbar:"#noticeToolBar",
				cellMinWidth:true,
				cols: [[
					{field: 'userId', title: '老师ID', align: "center"},
					{field: 'username',  title: '老师名称', align: "center"},
					{field: 'phone',  title: '老师电话', align: "center"},
					{field: 'userAge',  title: '年龄', align: "center"},
					{field: 'userSex',  title: '性别', align: "center",templet:function(d){
						return d.userSex==1?'男':'女';
					},width:80},
					{title: '操作', templet: '#noticeTableBar', fixed: "right", align: "center"}
				]],
				page: true
			});

			// 监听搜索操作
			form.on('submit(data-search-btn)', function (data) {
				var params= $("#searchFrm").serialize();
				//执行搜索重载
				table.reload('noticeTable', {
					page: {
						curr: 1
					}
					,url:api+'personnel/TeacherList?'+params
				});
				return false;
			});	
				
			//监听行数据的事件
			table.on('tool(noticeTable)', function (obj) {
				var data = obj.data;
				if(obj.event === 'update'){
					openSelectRole(data);
				}
			});
			
			var mainIndex;
			var url;  //动态的url
			
			//打开选择课程的弹出层
			function openSelectRole(data_table){
				var table_RolesIns;
				mainIndex=layer.open({
					type:1,
					title:'分配【'+data_table.username+'】老师的课程',
					content:$("#selectRoleDiv"),
					area:['1000px','90%'],
					btn:['<span class="layui-icon layui-icon-ok">确认分配</span>'],
					btnAlign:'c',
					yes:function(){
						var checkStatus = table.checkStatus('roleTable'); 
						var m=checkStatus.data;
						var uid=data_table.userId;
						var params="uid="+uid;
						$.each(m,function(x,item){
							params+="&Cids="+item.id;
						});
						 // alert(params);
						$.post(api+"personnel/setCourseTeacher",params,function(res){//修改老师课程
							layer.msg(res.msg);
							if (res.code == 200) {
								location.reload();//刷新界面
							}
						})
					},
					success:function(index){
					 table_RolesIns=table.render({
					       elem: '#roleTable',
					       url: api+'personnel/getCourseTeacher?userId='+data_table.userId,//查找老师的教授课程并且勾选
						   toolbar:false,
						   cellMinWidth:true,
					       cols: [[
					           {type: "checkbox",  fixed: "left"},
					           {field: 'id', title: 'ID', align: "center",width:120},
					           {field: 'name',  title: '课程标题', align: "center"},
					 		   {field: 'remark',  title: '课程备注', align: "center"}
					       ]]
					   });
					}
				});	
			}
			
			editor.customConfig.customAlert = function (info) {
				    layer.msg(info);
				};
				editor.create();
			
			});
</script>
</body>
</html>
